package com.gxa.saas.controller;

import com.gxa.saas.pojo.Department;
import com.gxa.saas.service.DepartmentService;
import com.gxa.saas.utils.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author wanghai
 * @date 2022/6/7 10:41
 */
@Api(value = "部门管理界面功能的说明")
@RestController
@RequestMapping("/department")
@CrossOrigin
public class DepartmentController {
    @Autowired
    DepartmentService departmentService;

    @ApiOperation("更新部门信息的操作")
    @PostMapping("/update")
    public Map updateDepartment(@RequestBody Department department){
        System.out.println(department);
        departmentService.updateDepartment(department);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        return jsonResult.getMap();
    }
    @ApiOperation("删除部门的操作")
    @PostMapping("/delete")
    public Map deleteDepartment(@RequestParam("id") Integer id){
        departmentService.deleteDepartment(id);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        return jsonResult.getMap();
    }
    @ApiOperation("添加部门的操作")
    @PostMapping("/add")
    public Map addDepartment(@RequestBody Department department){
        departmentService.addDepartment(department);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        return jsonResult.getMap();
    }
    @ApiOperation("更新启用状态的操作")
    @PostMapping("/updateIsUsed")
    public Map updateIsUsed(@RequestBody Department department){
        departmentService.updateIsUsed(department);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        return jsonResult.getMap();
    }

    @ApiOperation("分页查询")
    @PostMapping("/selectByPage")
    public Map selectByPage(@RequestBody Map map){
        List<Department> departments = departmentService.selectByPage(map);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setData(departments);
        return jsonResult.getMap();
    }

    @ApiOperation("全查询")
    @PostMapping("/getDepartmentList")
    public Map selectAll(){
        Integer departments = departmentService.selectAll();
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setData(departments);
        return jsonResult.getMap();
    }
}
